package cn.lili.modules.sms.serviceimpl;

import cn.lili.common.utils.BeanUtil;
import cn.lili.exchange.AmqpExchangeProperties;
import cn.lili.modules.sms.entity.dos.SmsReach;
import cn.lili.modules.sms.entity.dto.SmsReachDTO;
import cn.lili.modules.sms.mapper.SmsReachMapper;
import cn.lili.modules.sms.service.SmsReachService;
import cn.lili.routing.MsgRoutingKey;
import cn.lili.util.AmqpMessage;
import cn.lili.util.AmqpSender;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 短信任务业务层实现
 *
 * @author Bulbasaur
 * @since 2021/1/30 3:19 下午
 */
@Service
@RequiredArgsConstructor
public class SmsReachServiceImpl extends ServiceImpl<SmsReachMapper, SmsReach> implements SmsReachService {

    private final AmqpSender amqpSender;

    private final AmqpExchangeProperties amqpExchangeProperties;

    @Override
    public void addSmsReach(SmsReach smsReach,List<String> mobile) {
        SmsReachDTO smsReachDTO = new SmsReachDTO();
        BeanUtil.copyProperties(smsReach,smsReachDTO);
        smsReachDTO.setMobile(mobile);
        this.save(smsReach);
        amqpSender.send(AmqpMessage.builder()
                        .exchange(amqpExchangeProperties.getMsg())
                        .routingKey(MsgRoutingKey.SMS)
                        .message(smsReachDTO)
                .build());
    }
}
